package com.zengjianjun.hadoop.demo.controller;

import com.zengjianjun.hadoop.demo.client.MapReduceClient;
import com.zengjianjun.hadoop.demo.common.R;
import com.zengjianjun.hadoop.demo.executor.JobTypeEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * MapReduce操作相关接口
 *
 * @author zengjianjun
 */
@RestController
@RequestMapping("reduce")
public class MapReduceController {

    @Resource
    private MapReduceClient mapReduceClient;

    /**
     * 单词统计(统计指定key单词的出现次数)
     *
     * @param inputPath 文件路径，如果是文件的根路径，则默认分词该文件夹下所有的文件
     * @return 响应内容
     */
    @GetMapping("wordCount")
    public R<String> wordCount(@RequestParam String inputPath) {
        mapReduceClient.wordCount(JobTypeEnum.word_count, inputPath);
        return R.ok("单词统计成功");
    }
}
